/* eslint-disable react-refresh/only-export-components */
import React from "react";
import Navbar from "../../components/navbar";
import { useSearchParams } from "react-router-dom";
import TrainList from "./components/TrainList";
import TrainFooter from "./components/TrainFooter";
import styles from "./css/train.module.css";
import { getTrain } from "../../api/info";
import Navdate from "../../components/navdate";
function List() {
  let [sp] = useSearchParams();
  let start = sp.get("start");
  let end = sp.get("end");
  let date = sp.get("date");
  return (
    <div className={styles.box}>
      <Navbar title={start + " → " + end}></Navbar>
      <Navdate date={date} />
      <TrainList></TrainList>
      <TrainFooter />
    </div>
  );
}

export default List;
export const loader = async ({ request }) => {
  const url = new URL(request.url);
  const dat = Object.fromEntries(url.searchParams);
  const { data: res } = await getTrain(dat);

  return {
    list: res,
  };
};
